<!DOCTYPE HTML>
<html lang="zh-hans" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>计算 SmartMoney | 量化投资程序 帮助文档</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        <meta name="author" content="量化投资班二期 第1组">
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-back-to-top-button/plugin.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-chapter-fold/chapter-fold.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-expandable-chapters/expandable-chapters.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-splitter/splitter.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-code/plugin.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-auto-scroll-table/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../example/factorTest.html" />
    
    
    <link rel="prev" href="../example/iDStd-iDSkew-iDKurt.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="7.3"
        data-chapter-title="计算 SmartMoney"
        data-filepath="example/SmartMoney.md"
        data-basepath=".."
        data-revision="Sat Jul 24 2021 19:32:14 GMT+0800 (中国标准时间)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
                
                <li>
                    <a href="https://224466414.github.io/Quantitative_Investment_Help/" target="blank" class="custom-link">Home</a>
                </li>
            
            

            
            <li class="divider"></li>
            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        目录
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="getDate/getDate.html">
            
                
                    <a href="../getDate/getDate.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        日期获取模块 getDate
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="getDate/dateclass.html">
            
                
                    <a href="../getDate/dateclass.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        dateclass()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="getDate/dates.html">
            
                
                    <a href="../getDate/dates.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        针对日期的方法
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="getDate/dateclass.get_dates.html">
            
                
                    <a href="../getDate/dateclass.get_dates.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.1.</b>
                        
                        dateclass.get_dates()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="getDate/dateclass.get_beforeDate.html">
            
                
                    <a href="../getDate/dateclass.get_beforeDate.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.2.</b>
                        
                        dateclass.get_beforeDate()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="getDate/dateclass.get_afterDate.html">
            
                
                    <a href="../getDate/dateclass.get_afterDate.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.3.</b>
                        
                        dateclass.get_afterDate()
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="getDate/months.html">
            
                
                    <a href="../getDate/months.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        针对月份的方法
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="getDate/dateclass.get_months.html">
            
                
                    <a href="../getDate/dateclass.get_months.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.1.</b>
                        
                        dateclass.get_months()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="getDate/dateclass.get_BOMs.html">
            
                
                    <a href="../getDate/dateclass.get_BOMs.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.2.</b>
                        
                        dateclass.get_BOMs()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="getDate/dateclass.get_EOMs.html">
            
                
                    <a href="../getDate/dateclass.get_EOMs.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.3.</b>
                        
                        dateclass.get_EOMs()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="getDate/dateclass.get_DUMs.html">
            
                
                    <a href="../getDate/dateclass.get_DUMs.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.4.</b>
                        
                        dateclass.get_DUMs()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="getDate/dateclass.get_beforeMonth.html">
            
                
                    <a href="../getDate/dateclass.get_beforeMonth.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.5.</b>
                        
                        dateclass.get_beforeMonth()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="getDate/dateclass.get_afterMonth.html">
            
                
                    <a href="../getDate/dateclass.get_afterMonth.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.6.</b>
                        
                        dateclass.get_afterMonth()
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="getDate/cycles.html">
            
                
                    <a href="../getDate/cycles.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        针对周期的方法
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="getDate/dateclass.get_cycles.html">
            
                
                    <a href="../getDate/dateclass.get_cycles.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.1.</b>
                        
                        dateclass.get_cycles()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="getDate/dateclass.get_BOCs.html">
            
                
                    <a href="../getDate/dateclass.get_BOCs.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.2.</b>
                        
                        dateclass.get_BOCs()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="getDate/dateclass.get_EOCs.html">
            
                
                    <a href="../getDate/dateclass.get_EOCs.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.3.</b>
                        
                        dateclass.get_EOCs()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="getDate/dateclass.get_DUCs.html">
            
                
                    <a href="../getDate/dateclass.get_DUCs.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.4.</b>
                        
                        dateclass.get_DUCs()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="getDate/dateclass.get_beforeCycle.html">
            
                
                    <a href="../getDate/dateclass.get_beforeCycle.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.5.</b>
                        
                        dateclass.get_beforeCycle()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="getDate/dateclass.get_afterCycle.html">
            
                
                    <a href="../getDate/dateclass.get_afterCycle.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.6.</b>
                        
                        dateclass.get_afterCycle()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="getDate/dateclass.get_currentCycle.html">
            
                
                    <a href="../getDate/dateclass.get_currentCycle.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.7.</b>
                        
                        dateclass.get_currentCycle()
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="getStock/getStock.html">
            
                
                    <a href="../getStock/getStock.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        股票日频数据获取模块 getStock
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="getStock/stockclass.html">
            
                
                    <a href="../getStock/stockclass.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        stockclass()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="getStock/stockclass.read_data.html">
            
                
                    <a href="../getStock/stockclass.read_data.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        stockclass.read_data()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="getStock/stockclass.get_stockPools.html">
            
                
                    <a href="../getStock/stockclass.get_stockPools.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        stockclass.get_stockPools()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="getStock/stockclass.get_data.html">
            
                
                    <a href="../getStock/stockclass.get_data.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        stockclass.get_data()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="getStock/stockclass.get_names.html">
            
                
                    <a href="../getStock/stockclass.get_names.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        stockclass.get_names()
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="getQuote/getQuote.html">
            
                
                    <a href="../getQuote/getQuote.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        股票分钟频数据获取模块 getQuote
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="getQuote/quoteclass.html">
            
                
                    <a href="../getQuote/quoteclass.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        quoteclass()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="getQuote/quoteclass.read_data.html">
            
                
                    <a href="../getQuote/quoteclass.read_data.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        quoteclass.read_data()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="getQuote/quoteclass.get_data.html">
            
                
                    <a href="../getQuote/quoteclass.get_data.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        quoteclass.get_data()
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="getIndex/getIndex.html">
            
                
                    <a href="../getIndex/getIndex.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        指数数据获取模块 getIndex
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="getIndex/indexclass.html">
            
                
                    <a href="../getIndex/indexclass.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        indexclass()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="getIndex/indexclass.read_data.html">
            
                
                    <a href="../getIndex/indexclass.read_data.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        indexclass.read_data()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="getIndex/indexclass.get_data.html">
            
                
                    <a href="../getIndex/indexclass.get_data.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        indexclass.get_data()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="getIndex/indexclass.get_infos.html">
            
                
                    <a href="../getIndex/indexclass.get_infos.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        indexclass.get_infos()
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="factorProcess/factorProcess.html">
            
                
                    <a href="../factorProcess/factorProcess.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        因子处理模块 factorProcess
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="factorProcess/describe.html">
            
                
                    <a href="../factorProcess/describe.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        describe()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="factorProcess/winsorize.html">
            
                
                    <a href="../factorProcess/winsorize.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        winsorize()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="factorProcess/neutralize.html">
            
                
                    <a href="../factorProcess/neutralize.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        neutralize()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="factorProcess/normalize.html">
            
                
                    <a href="../factorProcess/normalize.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        normalize()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="factorProcess/standardize.html">
            
                
                    <a href="../factorProcess/standardize.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                        standardize()
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="factorTest/factorTest.html">
            
                
                    <a href="../factorTest/factorTest.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        因子检验模块 factorTest
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="factorTest/ICIRclass.html">
            
                
                    <a href="../factorTest/ICIRclass.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        ICIRclass()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="factorTest/ICIRclass.get_result.html">
            
                
                    <a href="../factorTest/ICIRclass.get_result.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        ICIRclass.get_result()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="factorTest/ICIRclass.save_result.html">
            
                
                    <a href="../factorTest/ICIRclass.save_result.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                        ICIRclass.save_result()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.4" data-path="factorTest/groupclass.html">
            
                
                    <a href="../factorTest/groupclass.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.4.</b>
                        
                        groupclass()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.5" data-path="factorTest/groupclass.get_result.html">
            
                
                    <a href="../factorTest/groupclass.get_result.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.5.</b>
                        
                        groupclass.get_result()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.6" data-path="factorTest/groupclass.save_result.html">
            
                
                    <a href="../factorTest/groupclass.save_result.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.6.</b>
                        
                        groupclass.save_result()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.7" data-path="factorTest/regressionclass.html">
            
                
                    <a href="../factorTest/regressionclass.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.7.</b>
                        
                        regressionclass()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.8" data-path="factorTest/regressionclass.get_result.html">
            
                
                    <a href="../factorTest/regressionclass.get_result.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.8.</b>
                        
                        regressionclass.get_result()
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.9" data-path="factorTest/regressionclass.save_result.html">
            
                
                    <a href="../factorTest/regressionclass.save_result.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.9.</b>
                        
                        regressionclass.save_result()
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7" data-path="example/example.html">
            
                
                    <a href="../example/example.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                        因子计算范例
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1" data-path="example/MKT-SMB-HML.html">
            
                
                    <a href="../example/MKT-SMB-HML.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.1.</b>
                        
                        计算 MKT/SMB/HML
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.2" data-path="example/iDStd-iDSkew-iDKurt.html">
            
                
                    <a href="../example/iDStd-iDSkew-iDKurt.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.2.</b>
                        
                        计算 iDStd/iDSkew/iDKurt
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="7.3" data-path="example/SmartMoney.html">
            
                
                    <a href="../example/SmartMoney.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.3.</b>
                        
                        计算 SmartMoney
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.4" data-path="example/factorTest.html">
            
                
                    <a href="../example/factorTest.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.4.</b>
                        
                        进行因子预处理与有效性检验
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    本书使用 GitBook 发布
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >量化投资程序 帮助文档</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="&#x8BA1;&#x7B97;-idstdidskewidkurt">&#x8BA1;&#x7B97; iDStd/iDSkew/iDKurt</h1>
<pre><code class="lang-python"><span class="hljs-comment"># -*- encoding: utf-8 -*-</span>
<span class="hljs-string">&apos;&apos;&apos;
Filename         :&#x65B9;&#x6B63;&#x8BC1;&#x5238;_003_SmartMoney.py
Description      :&#x8BE5;&#x6A21;&#x5757;&#x7528;&#x4E8E;&#x8BA1;&#x7B97;&#x56E0;&#x5B50; SmartMoney
Author           :&#x91CF;&#x5316;&#x6295;&#x8D44;1&#x7EC4;
Version          :1.0
&apos;&apos;&apos;</span>

<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
<span class="hljs-keyword">import</span> pandas <span class="hljs-keyword">as</span> pd
<span class="hljs-keyword">import</span> time, os, sys
<span class="hljs-keyword">from</span> collections <span class="hljs-keyword">import</span> OrderedDict
<span class="hljs-keyword">from</span> concurrent.futures <span class="hljs-keyword">import</span> ProcessPoolExecutor
sys.path.append(<span class="hljs-string">&apos;modules&apos;</span>)
<span class="hljs-keyword">from</span> getStock <span class="hljs-keyword">import</span> stockclass
<span class="hljs-keyword">from</span> getDate <span class="hljs-keyword">import</span> dateclass
<span class="hljs-keyword">from</span> getQuote <span class="hljs-keyword">import</span> quoteclass
<span class="hljs-keyword">import</span> basicFunction <span class="hljs-keyword">as</span> fun

<span class="hljs-comment"># &#x8BBE;&#x5B9A;&#x5F00;&#x59CB;&#x4E0E;&#x7ED3;&#x675F;&#x65E5;&#x671F;</span>
beginDate = <span class="hljs-string">&apos;20050101&apos;</span>
endDate = <span class="hljs-string">&apos;20210531&apos;</span>

<span class="hljs-comment"># &#x521B;&#x5EFA;&#x65E5;&#x671F;&#x6570;&#x636E;&#x83B7;&#x53D6;&#x5BF9;&#x8C61;</span>
dateClass = dateclass()
dates = dateClass.get_dates(beginDate, endDate, showProcess=<span class="hljs-keyword">False</span>)

<span class="hljs-comment"># &#x521B;&#x5EFA;&#x80A1;&#x7968;&#x65E5;&#x9891;&#x6570;&#x636E;&#x83B7;&#x53D6;&#x5BF9;&#x8C61;</span>
stockClass = stockclass(<span class="hljs-string">&apos;data/stock/1day&apos;</span>, preRead=[<span class="hljs-string">&apos;MVFloat&apos;</span>, <span class="hljs-string">&apos;PB&apos;</span>], showProcess=<span class="hljs-keyword">False</span>)
stockPools = stockClass.get_stockPools(dates, showProcess=<span class="hljs-keyword">False</span>)

<span class="hljs-comment"># &#x521B;&#x5EFA;&#x80A1;&#x7968;&#x5206;&#x949F;&#x9891;&#x6570;&#x636E;&#x83B7;&#x53D6;&#x5BF9;&#x8C61;</span>
quoteClass = quoteclass(<span class="hljs-string">&apos;data/stock/5min&apos;</span>)

<span class="hljs-comment"># &#x8BBE;&#x5B9A;&#x806A;&#x660E;&#x94B1;&#x5224;&#x5B9A;&#x9608;&#x503C;</span>
smartThreshold = <span class="hljs-number">0.2</span>

funStart = <span class="hljs-number">0</span>


<span class="hljs-comment"># &#x5B9A;&#x4E49;&#x8BA1;&#x7B97;&#x4E3B;&#x4F53;</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get_results</span><span class="hljs-params">(thisDate)</span>:</span>

    <span class="hljs-comment"># &#x83B7;&#x53D6;&#x5F53;&#x65E5;&#x8BC1;&#x5238;&#x6C60;</span>
    stockPool = stockPools[thisDate]

    <span class="hljs-comment"># &#x83B7;&#x53D6;&#x91CF;&#x4EF7;&#x6570;&#x636E;</span>
    dataOriginal = quoteClass.get_data(secIDs=stockPool, dates=[thisDate], fields=[<span class="hljs-string">&apos;Volume&apos;</span>, <span class="hljs-string">&apos;Open&apos;</span>, <span class="hljs-string">&apos;Close&apos;</span>], showProcess=<span class="hljs-keyword">False</span>)
    <span class="hljs-comment"># &#x8BA1;&#x7B97;&#x806A;&#x660E;&#x94B1;&#x5206;&#x949F;&#x6307;&#x6807;</span>
    factorOrder = pd.DataFrame(columns=stockPool)
    <span class="hljs-keyword">for</span> order <span class="hljs-keyword">in</span> range(<span class="hljs-number">0</span>, <span class="hljs-number">48</span>):
        <span class="hljs-keyword">if</span> order == <span class="hljs-number">0</span>:
            thisPrice = dataOriginal[dataOriginal[<span class="hljs-string">&apos;order&apos;</span>] == order][<span class="hljs-string">&apos;Open&apos;</span>]
            nextPrice = dataOriginal[dataOriginal[<span class="hljs-string">&apos;order&apos;</span>] == order][<span class="hljs-string">&apos;Close&apos;</span>]
            RetOrder = nextPrice / thisPrice - <span class="hljs-number">1</span>
        <span class="hljs-keyword">else</span>:
            lastPrice = dataOriginal[dataOriginal[<span class="hljs-string">&apos;order&apos;</span>] == order - <span class="hljs-number">1</span>][<span class="hljs-string">&apos;Close&apos;</span>]
            thisPrice = dataOriginal[dataOriginal[<span class="hljs-string">&apos;order&apos;</span>] == order][<span class="hljs-string">&apos;Close&apos;</span>]
            RetOrder = thisPrice / lastPrice - <span class="hljs-number">1</span>
        VolOrder = dataOriginal[dataOriginal[<span class="hljs-string">&apos;order&apos;</span>] == order][<span class="hljs-string">&apos;Volume&apos;</span>]
        factorOrder.loc[order, :] = np.abs(RetOrder) / np.sqrt(VolOrder)

    <span class="hljs-comment"># &#x8BA1;&#x7B97;&#x806A;&#x660E;&#x94B1;&#x6BCF;&#x65E5;&#x6307;&#x6807;</span>
    factorDate = OrderedDict()
    <span class="hljs-keyword">for</span> secID <span class="hljs-keyword">in</span> stockPool:
        <span class="hljs-comment"># &#x53D6;&#x5F97;&#x8BE5;&#x8BC1;&#x5238;&#x5F53;&#x65E5;&#x7684;&#x6570;&#x636E;&#xFF0C;&#x5E76;&#x8FDB;&#x884C;&#x6574;&#x7406;</span>
        factorSec = factorOrder[secID].sort_values(ascending=<span class="hljs-keyword">False</span>).replace(<span class="hljs-number">0</span>, np.nan).dropna()
        <span class="hljs-comment"># &#x83B7;&#x53D6;&#x806A;&#x660E;&#x94B1;&#x6240;&#x5728;K&#x7EBF;</span>
        <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> factorSec.empty:
            factorCum = factorSec.cumsum()
            <span class="hljs-keyword">for</span> index <span class="hljs-keyword">in</span> factorCum.index.tolist():
                <span class="hljs-keyword">if</span> factorCum.loc[index] &gt;= (factorSec.sum() * smartThreshold):
                    SmartIndex = factorCum[: index + <span class="hljs-number">1</span>].index.tolist()
                    <span class="hljs-keyword">break</span>
        <span class="hljs-keyword">else</span>:
            SmartIndex = []
        <span class="hljs-comment"># &#x8BA1;&#x7B97;&#x5F53;&#x65E5;&#x6240;&#x6709;&#x4EA4;&#x6613;&#x7684;&#x52A0;&#x6743;&#x5E73;&#x5747;&#x6210;&#x4EA4;&#x4EF7;</span>
        CloseAll = dataOriginal[dataOriginal[<span class="hljs-string">&apos;dates&apos;</span>] == thisDate][<span class="hljs-string">&apos;Close&apos;</span>]
        VolumeAll = dataOriginal[dataOriginal[<span class="hljs-string">&apos;dates&apos;</span>] == thisDate][<span class="hljs-string">&apos;Volume&apos;</span>]
        VWAPAll = (CloseAll * (VolumeAll / VolumeAll.sum())).sum()
        <span class="hljs-comment"># &#x8BA1;&#x7B97;&#x5F53;&#x65E5;&#x806A;&#x660E;&#x94B1;&#x4EA4;&#x6613;&#x7684;&#x52A0;&#x6743;&#x5E73;&#x5747;&#x6210;&#x4EA4;&#x4EF7;</span>
        CloseSmart, VolumeSmart = CloseAll[SmartIndex], VolumeAll[SmartIndex]
        VWAPSmart = (CloseSmart * (VolumeSmart / VolumeSmart.sum())).sum()
        <span class="hljs-comment"># &#x8BA1;&#x7B97;&#x8BE5;&#x8BC1;&#x5238;&#x7684;&#x5F53;&#x65E5;&#x806A;&#x660E;&#x94B1;&#x56E0;&#x5B50;</span>
        factorDate[secID] = VWAPSmart / VWAPAll

    <span class="hljs-comment"># &#x663E;&#x793A;&#x5F53;&#x524D;&#x8FDB;&#x5EA6;</span>
    index = dates[dates == thisDate].index.tolist()[<span class="hljs-number">0</span>]
    funcPerc = len(dates[: index]) / len(dates)
    fun.processing_bar(funcPerc, funStart)

    <span class="hljs-keyword">return</span> factorDate


<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&apos;__main__&apos;</span>:
    <span class="hljs-comment"># &#x8BA1;&#x7B97;&#x7A0B;&#x5E8F;&#x8FD0;&#x884C;&#x65F6;&#x95F4;</span>
    print(<span class="hljs-string">&apos;\n&#x56E0;&#x5B50;&#x8BA1;&#x7B97;&#x5F00;&#x59CB;&apos;</span>)
    funStart = time.perf_counter()

    <span class="hljs-comment"># &#x8BBE;&#x7F6E;&#x6570;&#x636E;&#x6846;&#x5B58;&#x50A8;&#x56E0;&#x5B50;</span>
    factorResult = OrderedDict()

    <span class="hljs-comment"># &#x4F7F;&#x7528;&#x591A;&#x8FDB;&#x7A0B;&#x5E76;&#x53D1;&#x8BA1;&#x7B97;</span>
    <span class="hljs-keyword">with</span> ProcessPoolExecutor() <span class="hljs-keyword">as</span> pool:
        results = pool.map(get_results, dates)
        results = list(zip(dates, results))

    <span class="hljs-comment"># &#x6574;&#x7406;&#x8BA1;&#x7B97;&#x7ED3;&#x679C;</span>
    <span class="hljs-keyword">for</span> date, result <span class="hljs-keyword">in</span> results:
        factorResult[date] = result

    print(<span class="hljs-string">&apos;\n&#x56E0;&#x5B50;&#x8BA1;&#x7B97;&#x5B8C;&#x6210;&apos;</span>)

    <span class="hljs-comment"># &#x5C06;&#x6240;&#x6709;&#x671F;&#x9650;&#x7684;&#x6240;&#x6709;&#x8BC1;&#x5238;&#x7684;&#x56E0;&#x5B50;&#x503C;&#x8F6C;&#x53D8;&#x4E3A;&#x6570;&#x636E;&#x6846;&#x7C7B;&#x578B;(pd.DataFrame)</span>
    factorResult = pd.DataFrame(factorResult)
    factorResult.index = pd.Series(factorResult.index, name=<span class="hljs-string">&apos;secIDs&apos;</span>)

    <span class="hljs-comment"># &#x8F93;&#x51FA;&#x8BA1;&#x7B97;&#x7ED3;&#x679C;</span>
    print(factorResult)

    <span class="hljs-comment"># &#x5B58;&#x50A8;&#x8BA1;&#x7B97;&#x7ED3;&#x679C;</span>
    pathResult = <span class="hljs-string">&apos;factor/&#x65B9;&#x6B63;&#x8BC1;&#x5238;_003&apos;</span>
    <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> os.path.exists(pathResult):
        os.makedirs(pathResult)
    factorResult.to_csv(<span class="hljs-string">&apos;{}/&#x65B9;&#x6B63;&#x8BC1;&#x5238;_003_SmartMoney.csv&apos;</span>.format(pathResult))
</code></pre>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../example/iDStd-iDSkew-iDKurt.html" class="navigation navigation-prev " aria-label="Previous page: 计算 iDStd/iDSkew/iDKurt"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../example/factorTest.html" class="navigation navigation-next " aria-label="Next page: 进行因子预处理与有效性检验"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-back-to-top-button/plugin.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-splitter/splitter.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-code/plugin.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-auto-scroll-table/plugin.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"back-to-top-button":{},"chapter-fold":{},"expandable-chapters":{},"splitter":{},"popup":{},"code":{"copyButtons":true},"auto-scroll-table":{},"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":false,"twitter":false,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":[]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
